/*
Javascript Component
Copyright (c) 2007, Alimama! Inc. All rights reserved.
Code licensed under the New BSD License
version: 0.1
Created Date: 2007-5-1
*/

/**
 * Returns a random integer number between the two passed in values.
 * @function: $random
 * @param	{integer}	the minimum value (inclusive).
 * @param	{integer}	the maximum value (inclusive).
 * @return a random integer between min and max.
*/

function $random(min, max){
	return Math.floor(Math.random() * (max - min + 1) + min);
};

var $w = window;
var $d = document;
var $l = location;
function $(s){return $d.getElementById(s);}
function $i(s){return $d.getElementById(s);}
function $t(s){return $d.getElementsByTagName(s);}
function $n(s){return $d.getElementsByName(s);}

/**
 * The _jsc object is the single global object used by JSC Library.  It
 * contains utility function for setting up global vars, inheritance, and
 * so on.  
 * @module jsc
 * @title  JSC Global
 */

if (typeof _jsc == "undefined") {
	/**
	 * The JSC global namespace object.  If _jsc is already defined, the
     * existing _jsc object will not be overwritten so that defined
     * namespaces are preserved.
     * @class _jsc
     * @static
     */
	var _jsc = {};
};

if (typeof _jschome == "undefined") {
	/**
	 * The JSC path.
	 */
	var _jschome = 'jsc/';
};

// Components的初始化完成标志
_jsc.loaded = false;

/**
 * Returns the namespces specified and creates it if it doesn't exist
 * 
 * @method namespace
 * @static
 * @param	{String*}	arguments 1-n namespaces to create
 * @return	{Object}	A reference to the last namespace object created
 */
_jsc.namespace = function() {
	var a = arguments, o = null, d, j;
	for (var i=0; i < a.length; i++) {
		d = a[i].split(".");
		o = _jsc;
		
		// ignored _jsc if it is included
		for (j=(d[0] == "_jsc") ? 1 : 0; j < d.length; j++) {
			o[d[j]] = o[d[j]] || {};
			o = o[d[j]];
		};
	};
};

/**
 * Creating global namespces
 * @method init_namespaces
 * @static
 * @private
 */
(function() {
	_jsc.namespace("class", "util", "dom", "ajax", "client", "evt", "his", "state", "mgr");
})();
